< previous page page_270 next page >

Page 270
analysis.gifIn the Click event of the cmdNew command button, you invoke the AddNew method on the Recordset object of the data control. This actually moves the record pointer to the phantom record in the recordset. By moving to the phantom record, the data control will update the controls bound to it. Because the phantom record is blank, all blank data will display in the controls, which signifies to the user that a new record can be entered. You also set the focus to the txtFirst text box using the SetFocus method.

Saving the Data
Once the buttons have been toggled to their opposite state, about the only thing the user can do is click the Save or Cancel button. You now need to add the code under the Save command button and the Cancel command button to perform their respective actions. Under the Click event of the Save button, youll use the Update method of the Recordset object to move the data from the controls into the recordset, which will then update the table in the database.
EXERCISE
Adding Code to the Save Button
1. Add the following code under the cmdSave command button by double-clicking on the Save command button.
Private Sub cmdSave_Click()
Dim boolAdding As Boolean

boolAdding = (datEmployees.Recordset.EditMode = adEditAdd)

datEmployees.Recordset.Update
If boolAdding Then
datEmployees.Recordset.MoveLast
End If
Call ToggleButtons
End Sub
analysis.gifThe first thing you need to check in the Save command buttons Click event is to see whether youre in add or edit mode. You can do this by checking the EditMode property of the Recordset object against a constant adEditAdd. Youll use this flag to determine whether you stay on

 
< previous page page_270 next page >

If you like this book, buy it!